import React, { Component } from 'react'
import PubSub from 'pubsub-js'
import Far from './Far'

export default class App extends Component {
  render() {
    const appId = PubSub.subscribe('xxx', (topic, data) => {
      console.log('app-xxx', topic, data)
    })
    PubSub.subscribe('yyy', (topic, data) => {
      console.log('app-yyy', topic, data)
    })
    return (
      <div>
        App
        <hr />
        <button
          onClick={() => {
            PubSub.unsubscribe(appId)
          }}
        >
          清除app组件中订阅的xxx话题
        </button>
        <button
          onClick={() => {
            PubSub.unsubscribe('xxx')
          }}
        >
          清除xxx话题所对应的所有订阅
        </button>
        <button
          onClick={() => {
            PubSub.clearAllSubscriptions()
          }}
        >
          清除所有订阅
        </button>
        <hr />
        <Far></Far>
      </div>
    )
  }
}
